<template>
	<view>
		<u-navbar placeholder fixed autoBack border title="单位详情"></u-navbar>
		<view class="d-p-30" v-if="info">
			<view class="card d-p-30">
				<view class="d-flex d-m-b-20">
					<view class="d-font-30 d-flex-1" style="color: #151C24;">单位信息</view>
					<view>
						<!-- 到单位详情 -->
						<u-button
							text="查看单位"
							shape="circle"
							size="mini"
							:customStyle="{
								color: '#FFB61D',
								borderColor: '#FFB61D'
							}"
							@click="enterprise"
						></u-button>
					</view>
				</view>
				<view class="u-border-bottom d-flex d-font-28" style="height: 80rpx;">
					<view class="" style="color: #949AA2;">单位名称</view>
					<view class="d-flex-1 d-text-right d-p-l-30" style="color: #162233;">{{ info.qymc || info.fbDwmc || '无数据源' }}</view>
				</view>
				<view class="u-border-bottom d-flex d-font-28" style="height: 80rpx;">
					<view class="d-flex-1" style="color: #949AA2;">统一社会信用代码</view>
					<view style="color: #162233;">{{ info.tyshxydm || '无数据源' }}</view>
				</view>
				<view class="u-border-bottom d-flex d-font-28" style="height: 80rpx;">
					<view class="" style="color: #949AA2;">单位地址</view>
					<view class="d-flex-1 d-text-right d-p-l-30" style="color: #162233;">{{ info.qyjydz || info.qydz || '无数据源' }}</view>
				</view>
				<view class="u-border-bottom d-flex d-font-28" style="height: 80rpx;">
					<view class="d-flex-1" style="color: #949AA2;">单位类型</view>
					<view style="color: #162233;">{{ info.qylx || info.djzclx || '无数据源' }}</view>
				</view>
				<view class="u-border-bottom d-flex d-font-28" style="height: 80rpx;">
					<view class="d-flex-1" style="color: #949AA2;">属地</view>
					<view style="color: #162233;">{{ info.districtName || '无数据源' }}</view>
				</view>
				<view class="u-border-bottom d-flex d-font-28" style="height: 80rpx;">
					<view class="d-flex-1" style="color: #949AA2;">主项资质类别</view>
					<view style="color: #162233;">{{ info.zzlb || info.zhuxiangzizhi || '无数据源' }}</view>
				</view>
				<view class="u-border-bottom d-flex d-font-28" style="height: 80rpx;">
					<view class="d-flex-1" style="color: #949AA2;">资质等级</view>
					<view style="color: #162233;">{{ info.dj || info.grade || '无数据源' }}</view>
				</view>
				<!-- 分包单位 证书号没有说明 主包待定 参建有 -->
				<template v-if="current != 5">
					<view class="u-border-bottom d-flex d-font-28" style="height: 80rpx;">
						<view class="d-flex-1" style="color: #949AA2;">资质证书号</view>
						<view style="color: #162233;">{{ info.frdbzjhm || '无数据源' }}</view>
					</view>
				</template>
				<view class="u-border-bottom d-flex d-font-28" style="height: 80rpx;">
					<view class="d-flex-1" style="color: #949AA2;">联系电话</view>
					<view><u--text color="#21A5F3" size="28rpx" mode="phone" call :text="info.dwdh || info.buildingleaderphone || '无数据源'"></u--text></view>
				</view>
				<!-- 分包单位 传真没有 主包待定 参建有 -->
				<template v-if="current != 5">
					<view class="u-border-bottom d-flex d-font-28" style="height: 80rpx;">
						<view class="d-flex-1" style="color: #949AA2;">传真</view>
						<view style="color: #162233;">{{ info.qyczhm || '无数据源' }}</view>
					</view>
				</template>
				<!-- 分包单位才有的信息 -->
				<template v-if="current == 5">
					<view class="u-border-bottom d-flex d-font-28" style="height: 80rpx;">
						<view class="d-flex-1" style="color: #949AA2;">分包类型</view>
						<view style="color: #162233;">{{ info.fblx || '无数据源' }}</view>
					</view>
					<view class="u-border-bottom d-flex d-font-28" style="height: 80rpx;">
						<view class="d-flex-1" style="color: #949AA2;">合同造价</view>
						<view style="color: #162233;">{{ info.htzj || '0' }}万元</view>
					</view>
					<view class="u-border-bottom d-flex d-font-28" style="height: 80rpx;">
						<view class="d-flex-1" style="color: #949AA2;">分包标段名称</view>
						<view style="color: #162233;">{{ info.fbbdmc || '无数据源' }}</view>
					</view>
					<view class="u-border-bottom d-flex d-font-28" style="height: 80rpx;">
						<view class="d-flex-1" style="color: #949AA2;">开工日期</view>
						<view style="color: #162233;">{{ info.kgsj || '无数据源' }}</view>
					</view>
					<view class="u-border-bottom d-flex d-font-28" style="height: 80rpx;">
						<view class="d-flex-1" style="color: #949AA2;">竣工日期</view>
						<view style="color: #162233;">{{ info.jgsj || '无数据源' }}</view>
					</view>
				</template>
			</view>

			<view class="card d-m-t-30 d-p-30">
				<view class="d-flex d-m-b-20"><view class="d-font-32 d-flex-1" style="color: #151C24;font-weight: bold;">附件</view></view>
				<view class="table">
					<view class="tr">
						<view class="th d-p-l-30">序号</view>
						<view class="th">附件</view>
						<view class="th">数量</view>
					</view>
					<template v-if="atta && atta.length > 0">
						<view class="tr" v-for="(item, index) in atta" :key="index" @click="viewImage(item)">
							<view class="td d-p-l-30">{{ index + 1 }}</view>
							<view class="td u-line-1">
								<text style="color: #21A5F3;">{{ item.attachName }}</text>
							</view>
							<view class="td">{{ item.count }}</view>
						</view>
					</template>
				</view>
				<template v-if="!atta || atta.length <= 0">
					<view class="d-p-30"><u-empty icon="/static/image/none.png" text="暂无附件"></u-empty></view>
				</template>
			</view>
		</view>
	</view>
</template>

<script>
import { deptDetail, subInfoBy, appAtta } from '../../../common/api.js';
export default {
	data() {
		return {
			current: null,
			id: null,
			info: null,
			atta: null
		};
	},
	onLoad(e) {
		this.current = e.current;
		this.id = e.id;
		this.init();
	},
	methods: {
		init() {
			// current 0建设单位 1勘查单位 2总包单位 3监理单位 4设计单位 5分包单位
			if (this.current != 5) {
				// 参建单位
				deptDetail({
					id: this.id
				}).then(e => {
					this.info = e.data;
					// 附件获取
					appAtta({
						params: {
							ywlx: this.info.ywlx,
							ywbh: this.id
						}
					}).then(e => {
						this.atta = e.data;
					});
				});
			} else if (this.current == 5) {
				// 分包单位
				subInfoBy({
					params: {
						id: this.id
					}
				}).then(e => {
					this.info = e.data;
					// 附件获取
					appAtta({
						params: {
							ywlx: this.info.ywlx,
							ywbh: this.id
						}
					}).then(e => {
						this.atta = e.data;
					});
				});
			} else {
				uni.$u.toast('未知类型或未对接接口');
			}
		},
		enterprise() {
			// 参建单位没有 单位编号 传 ID 不知道对不对
			uni.$u.route({
				url: '/pages/index/enterprise/enterprise',
				params: {
					id: this.info.fbDwbh || this.info.id
				}
			});
		},
		viewImage(item) {
			if (!item.attachList || item.attachList.length <= 0) {
				return uni.$u.toast('暂无可查看附件');
			}
			uni.previewImage({
				urls: item.attachList.map(e => {
					return e.attachUrl;
				})
			});
		}
	}
};
</script>

<style lang="scss">
.card {
	box-shadow: 0rpx 5rpx 10rpx rgba(0, 0, 0, 0.05);
	border-radius: 10rpx;
	background-color: #ffffff;
	.table {
		font-size: 28rpx;
		display: table;
		width: 100%;
		vertical-align: middle;
		border: 1px solid #f6f7f8;
		.tr {
			display: table-row;
			.th,
			.td {
				display: table-cell;
				height: 80rpx;
				vertical-align: middle;
			}
			.th {
				font-weight: bold;
				color: #162233;
			}
			&:nth-child(2n-1) {
				background-color: #f6f7f8;
			}
		}
	}
}
page {
	background-color: #fbfcfc;
}
</style>
